﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPFServices.Models;
using WPFServices.Models.Domain;

namespace WPFServices.Services.DomainService.Productinfo
{
    public class ProductService
    {
        private readonly ApiClient _apiClient;

        public ProductService()
        {
            _apiClient = new ApiClient();
        }

        /// <summary>
        /// 获取所有产品（新增选择）
        /// </summary>
        public async Task<ApiPaging<List<ProductDto>>> SearchProductAsync(SearchProductDto searchProductDto)
        {
            var queryParams = $"PageIndex={searchProductDto.PageIndex}&PageSize={searchProductDto.PageSize}";


            var result = await _apiClient.GetAsync<ApiPaging<List<ProductDto>>>($"Product/GetProducts?{queryParams}");
            if (result.IsSuc && result.code == ResultCode.Ok)
            {
                return result.data;
            }
            else
            {
                throw new Exception($"获取产品列表失败: {result.msg}");
            }
        }
    }
}
